home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16473 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  993 b 

  1. Path: cityscape.co.uk!usenet
  2. From: es07@cityscape.co.uk (David Ascroft)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: new with multidimensional arrays
  5. Date: 11 Apr 1996 00:01:12 GMT
  6. Organization: IP-GOLD User
  7. Message-ID: <4khi48$m2d@news.cityscape.co.uk>
  8. References: <3169B9C3.2A10@MIT.EDU>
  9. NNTP-Posting-Host: cises07.demon.co.uk
  10. X-Newsreader: WinVN 0.92.6+
  11.  
  12. In article <3169B9C3.2A10@MIT.EDU>, Darrel K Robertson <dkr1@MIT.EDU> says:
  13. >
  14. >Hi, I wonder if anyone can help me. I want to use "new" to create a 
  15. >multidimensional array, but don't know how. So far I have:
  16. >complex *grid;
  17. >scanf("%d %d", &nc, &nr);
  18. >grid = new complex[nc][nr];
  19. >
  20. >Unfortunately this won't work. Any info would be much appreciated.
  21. >Darrel.
  22.  
  23. Try this (with nc and nr being the size of the two-dimensional array):
  24.  
  25.     // First coordinate.
  26.     complex **grid = new complex *[nc];
  27.  
  28.     // For each first coordinate, allocate the corresponding second.
  29.     for (int x = 0; x < nc; x++)
  30.         grid[x] = new complex[nr];
  31.  
  32. Dave
  33.